package org.jeecg.modules.tt_question_collect.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.jeecg.modules.tt_question_collect.entity.TtQuestionCollect;
import org.jeecg.modules.tt_question_collect.entity.TtQuestionDealRecord;
import org.jeecg.modules.tt_question_collect.entity.tspmodel;

import java.util.List;
import java.util.Map;

/**
 * @Description: 问题收集表
 * @Author: jeecg-boot
 * @Date: 2021-01-29
 * @Version: V1.0
 */
public interface TtQuestionCollectMapper extends BaseMapper<TtQuestionCollect> {


    List<TtQuestionCollect> querySysCementListByUserId(Page<TtQuestionCollect> page, @Param("ttQuestionCollect") TtQuestionCollect ttQuestionCollect);

    List<tspmodel> querysplist(Page<tspmodel> page, @Param("tspmodel") tspmodel tspmodel);

    List<TtQuestionCollect> queryquestionList(Page<TtQuestionCollect> page, @Param("ttQuestionCollect") TtQuestionCollect ttQuestionCollect);


    @Select("select * from   tt_question_deal_record  where questioncode = '${questioncode}' and dealid = ${id}")
    TtQuestionDealRecord querybyquestioncode(@Param("questioncode") String questioncode, @Param("id") String id);


    @Select("select a.* from sys_depart a  INNER JOIN sys_user_depart b  on a.id = b.dep_id where b.user_id = '${id}'")
    List<Map<String, Object>> querydetplist(@Param("id") String id);


    @Select(" select flowcode from tt_collect_flow where flowtype ='${lclx}' and  dbms_lob.instr(dept,'${bmid}',1,1) <> 0")
    String queryidBybmid(String bmid,String lclx);

    @Update("update tt_question_collect set jiraid = '${jiraId}', jirakey = '${jiraKey}', isjira = '1' where id = '${id}'")
    void setJiraIdOrKey(@Param("id") String id, @Param("jiraId") String jiraId, @Param("jiraKey") String jiraKey);

    @Update("update tt_question_collect set dealstatus = '${name}' where id = '${id}'")
    int setJiraStatu(String id, String name);

    @Update("update tt_question_collect set scbj = '1' where id = '${id}'")
	void updatescbjbyid(@Param("id") String id);

    @Select("select substr('00000' ||  question_code_asc.nextval,-6)  xlcode from dual")
    String cxxl();

    @Select("select a.role_name,a.role_code from sys_role a join sys_user_role b on a.id= b.role_id where user_id = '${userid}'")
    List<Map<String, Object>> getrolelist(String userid);

    @Select("select id,questioncode,jiraid from tt_question_collect where isjira ='1' and auditstatus ='2' and fashbj = '2' and scbj = '0' and (sftbjirabj is null or sftbjirabj ='1') and dealstatus != '完成' and dealstatus != '发布完成' ")
    List<Map<String, Object>> queryupdatejiralist();

    @Select("select id,titlesummary,questioncode,jiraid,isjira from tt_question_collect where (isjira ='0' or isjira is null) and auditstatus ='2' and fashbj = '2' and scbj = '0' and (sftbjirabj is null or sftbjirabj ='1')")
    List<Map<String, Object>> getjiratblist();

    @Select("select count(a.id)from tt_question_collect a INNER JOIN tt_audit_record b on a.id = b.tableid where b.isnew != '0' and b.scbj = '0' and b.audituserid = '#{id}'  and b.lclx = 'wtlx'")
    String queryuserdspcount(@Param("id") String id);

}
